package com.tempname.project4;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class ImageAdapter extends BaseAdapter {

    private Activity activity;
    private static LayoutInflater inflater=null;
    private int currentImage;

    public ImageAdapter(Activity a) {
        activity = a;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        
    }
    
    
    public int getCurrentImage(){
    	return currentImage;
    }


    public int getCount() {
        return data.length;
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public static class ViewHolder{
        public TextView text;
        public ImageView image;
    }
    

    public View getView(int position, View convertView, ViewGroup parent) {
    	//System.out.println("position " + position);
        View vi=convertView;
        ViewHolder holder;
        if(convertView==null){
            vi = inflater.inflate(R.layout.image_gallery_items, null);
            holder=new ViewHolder();
            holder.text=(TextView)vi.findViewById(R.id.textView1);
            holder.image=(ImageView)vi.findViewById(R.id.image);
            vi.setTag(holder);

        }
        else{
            holder=(ViewHolder)vi.getTag(); }
        

        holder.text.setText(name[position]);
        final int stub_id=data[position];
        holder.image.setImageResource(stub_id);
        currentImage = position;
        return vi;
    }

    private int[] data = {
            R.drawable.foto1, R.drawable.foto2,
            R.drawable.foto3, R.drawable.foto4,
            R.drawable.foto5
    };
    
    private String[] name = {
            "Image1", "Image2",
            "Image3", "Image4",
            "Image5"
    };

}
